// pages/cooperation/com/com-result-pop/com-result-pop.js
let animation;
const app = getApp()
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    model: {
      type: Object,
      default: {}
    },
    total: {
      type: Number,
      default: 0
    }
  },

  options: {
    styleIsolation: "apply-shared",
    addGlobalClass: true,
  },

  /**
   * 组件的初始数据
   */
  data: {
    completedUrl: app.globalData.cdnResourceUrl + 'status_update_1.png',
    uncompletedUrl: app.globalData.cdnResourceUrl + 'status_update_2.png',
    visible: false,
    animationData: {},
  },

  lifetimes: {
    attached: function () {
      if (!animation) {
        animation = wx.createAnimation({
          duration: 400,
          timingFunction: "ease",
        });
      }

      setTimeout(() => {
        this.fadeAway(0);
      }, 50);
    },
    detached: function () {
      // 在组件实例被从页面节点树移除时执行
    },
  },

  /**
   * 组件的方法列表
   */
  methods: {
    fadeAway(target) {
      this.data.visible = target == 0;
      animation.translateY(target).step();
      this.setData({
        animationData: animation.export(),
      });
    },

    handleAnimationend() {
      if (!this.data.visible) {
        this.triggerEvent('onresulthide')
      }
    },

    handleClose() {
      this.fadeAway(1000);
    },

    handleLeave() {
      this.triggerEvent('onresultleave')
    },
  }
})
